<template>
	<view class="bore">
		<view class="context1">
			<text class="changqu"> 所在厂区</text>
			<uni-data-select class="select" v-model="chang" :localdata="range" @change="change"></uni-data-select>
		</view>
		<view class="xuanze">
			<view class="uni-padding-wrap uni-common-mt test">
				<uni-segmented-control activeColor="#48486c" :current="current" :values="items"
					@clickItem="onClickItem" />
			</view>
			<view class="content">
				<view v-if="current === 0">
					<boarInformation v-for="(item,index) in boarlist" :key="index" :data="boarlist[index]"></boarInformation>
				</view>
				<view v-if="current === 1">
					<boarTransferVue v-for="(item,index) in boartransfer" :key="index" :data="boartransfer[index]"></boarTransferVue>
				</view>
				<view v-if="current === 2">
					<text class="content-text">猪只死亡的内容</text>
				</view>
				<view v-if="current === 3">
					<text class="content-text">猪只称重的内容</text>
				</view>
			</view>
		</view>
	</view>

</template>

<script>
import boarInformation from './content/boarInformation.vue';
import boarTransferVue from './content/boarTransfer.vue';
import { boarformation, bortransfer } from '@/api/pig/boar.js';

export default {
  components: {
    boarInformation,
    boarTransferVue
  },
  data() {
    return {
      value: -1,
      current: 0,
      items: ['信息总览', '猪只转舍', '猪只死亡', '猪只称重'],
      chang: 0,
      range: [
        { value: 0, text: "1号厂区" },
        { value: 1, text: "2号厂区" },
        { value: 2, text: "3号厂区" },
      ],
      boarlist: [],
	  boartransfer:[],
      boarQueryInformationReq: {
        pageSize: 4,
        pageNum: 1,
        FactoryID: -1
      },
      deviceData: [
        {
          code: 'ZZ202409939821',
          FactoryName: '场区',
          deptName: '399',
          status: 'SALE',
          earCode: '11457',
          parity: '1',
          remark: '保育猪多栏位入栏',
          createdTime: '2024-09-02 20:01:22',
          createdBy: '1'
        },
        {
          code: 'ZZ202409939821',
          FactoryName: '场区',
          deptName: '399',
          status: 'SALE',
          earCode: '11457',
          parity: '1',
          remark: '保育猪多栏位入栏',
          createdTime: '2024-09-02 20:01:22',
          createdBy: '1'
        }
      ]
    };
  },
  methods: {
    onClickItem(e) {
      if (this.current !== e.currentIndex) {
        this.current = e.currentIndex
      }
    },
    change(e) {
      this.value = e; // 确保更新 value
      this.boarQueryInformationReq.FactoryID = this.value; // 更新请求参数
      this.getboarInformation(); // 重新获取数据
	  this.getboarTranfer();
    },
    getboarInformation() {
      boarformation(this.boarQueryInformationReq).then((res) => {
        console.log(res);
        this.boarlist = res.data.list;
      }).catch(error => {
        console.error('获取公猪信息失败:', error);
      });
    },
	getboarTranfer() {
		bortransfer(this.boarQueryInformationReq).then((res) =>{
			console.log(res);
			this.boartransfer = res.data.list;
		}).catch(error =>{
			console.error('获取公猪转舍信息失败：', error)
		})
	}
  },
  created() {
    this.boarQueryInformationReq.FactoryID = this.value; // 在 created 钩子中设置
    this.getboarInformation();
	this.getboarTranfer();
  }
};
</script>

<style lang="scss" scoped>
	/deep/ .segmented-control__item--button--first {
		border-top-left-radius: 20px;
		border-bottom-left-radius: 20px;
	}

	/deep/ .segmented-control__item--button--last {
		border-top-right-radius: 20px;
		border-bottom-right-radius: 20px;
	}


	.title {
		display: flex;

		background-color: blue;

		image {
			width: 50px;
		}
	}

	.title {
		text {
			text-align: center;
			color: white;

		}
	}

	.context1 {
		width: 95%;
		display: flex;
	}

	.changqu {
		text-align: center;
		width: 100px;
		height: 50px;
		line-height: 50px;
	}

	.bore {
		.uni-padding-wrap {
			width: 85%;
			margin: auto;
		}
	}
</style>